import csv
from datetime import datetime, timedelta
with open('../data/apply_imei_20181120_sort.csv') as csv_file:
    csv_reader = csv.reader(csv_file, delimiter='\t')

    with open('../data/apply_imei_20181120_format_sort.csv', mode='w') as employee_file:
        employee_writer = csv.writer(employee_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
        for row in csv_reader:
            imei = row[0]
            applyDate = row[1]
            endDate = applyDate
            startDate = (datetime.strptime(applyDate, '%Y%m%d') - timedelta(days=90)).strftime('%Y%m%d')
            employee_writer.writerow([imei, startDate, endDate])
